import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

public class Code284 {

    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3};
        PeekingIterator peekingIterator = new PeekingIterator(a);
        System.out.println(peekingIterator.next());    // 返回 1 ，指针移动到下一个元素 [1,2,3]
        System.out.println(peekingIterator.peek());    // 返回 2 ，指针未发生移动 [1,2,3]
        System.out.println(peekingIterator.next());    // 返回 2 ，指针移动到下一个元素 [1,2,3]
        System.out.println(peekingIterator.next());    // 返回 3 ，指针移动到下一个元素 [1,2,3]
        System.out.println(peekingIterator.hasNext()); // 返回 False


    }
}

class PeekingIterator implements Iterator<Integer> {


    List<Integer> arrayList = new ArrayList<>();
    int index = 0;

    public PeekingIterator(Iterator<Integer> iterator) {
        while (iterator.hasNext()){
            Integer next = iterator.next();
            arrayList.add(next);
        }

    }

    public PeekingIterator(int[] a) {
        for (int i = 0; i < a.length; i++) {
            arrayList.add(a[i]);
        }
    }

    public boolean hasNext() {
        return arrayList.size() > index;

    }

    public Integer next() {
        if (arrayList.size()!=0){
            Integer integer = arrayList.get(index);
            ++index;
            return integer;
        }
        return null;

    }

    public void remove() {

    }

    public void forEachRemaining(Consumer<? super Integer> action) {

    }

    public Integer peek() {
        Integer integer = arrayList.get(index);
        return integer;
    }
}